#include "stdlib.h"
#include "stdio.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "unistd.h"
#include "linux/input.h"

int main(int argc, char *argv[])
{
    struct input_event in_ev;
    int fd = -1;
    int len;

    len = sizeof(struct input_event);

    if ( argc != 2 ) {
        fprintf(stderr, "usage: %s <input-dev>\n", argv[0]);
        exit(-1);
    }

    if ( (fd = open(argv[1], O_RDONLY)) < 0 ) {
        perror("open error");
        exit(-1);
    }

    while (1) {
        
        if ( read(fd, &in_ev, len) != len ) {
            perror("read error");
            exit(-1);
        }

        printf("type:%d code:%d value:%d\n",in_ev.type, in_ev.code, in_ev.value);
    }

    exit(0);
}